//图片懒加载
function ImgLoading(imgList) {
  /* 预加载图片 **/
  var imgList = imgList;

  function ForDight(Dight, How) {
    Dight = Math.round(Dight * Math.pow(10, How)) / Math.pow(10, How);
    return Dight;
  }

  function maxWH(obj, maxW, maxH) {
    var w = $(window).width() * 2,
      h = $(window).height() * 2,
      rat = ForDight(Math.min(w / maxW, h / maxH), 2);
    alert(rat + '|' + w + '|' + h + '|' + rat);
    $('html').attr('style', "font-size:" + ForDight((rat * h / 2), 2) + "px; line-height:" + ForDight((rat * h / 2), 2) + "px");
    $(obj).css({
      "width": ForDight((rat * maxW / w * 100), 2) + "%",
      "height": ForDight((rat * maxH / h * 100), 2) + "%"
    });
  }

  function imgReady(arr, callback, n) {
    if (n && n > 0) {
      var img = new Image();
      img.src = arr[n - 1];
      if (img.complete) {
        n--;
      }
      img.onload = function () {
        n--;
      }
      $('.spinner .size').text(ForDight((arr.length - n) / arr.length * 100, 0) + '%');
      setTimeout(function () {
        imgReady(arr, callback, n);
      }, 10);
    } else {
      if (callback) {
        callback(arr);
      }
    }
  };
  var slide4D, getImgListArr = [];
  getImgListArr.images = document.images;
  getImgListArr.n = getImgListArr.images.length;

  function getImgList(list, n, callback) {
    if (n && n > 0) {
      n--
      list.push(getImgListArr.images[n].src);
      setTimeout(function () {
        getImgList(list, n, callback)
      }, 10);
    } else {
      if (callback) {
        callback(list)
      }
    }
  }
  window.onload = function () {
    getImgList(imgList, getImgListArr.n, function (imgList) {
      imgReady(imgList, function (i) {
        $("#loading").hide();
        $(".content").show();

      }, imgList.length);
    });

  }
}

$(function () {
  ImgLoading([]);
  var details = {
    init: function () {
      this.domEventBind();
    },
    domEventBind: function () {
      $(".tab div").on("click", function () {
        $(".tab div").removeClass("active");
        $(this).addClass("active");
        if ($(this).hasClass("details")) {
          $(".gifts-wrapper").css("display", "none");
          $(".details-wrapper").css("display", "block");
        }else{
          $(".gifts-wrapper").css("display", "block");
          $(".details-wrapper").css("display", "none");
        }
      })
    }
  }
  details.init();
})